// pages/seeArchives/seeArchives.js
var request = require("../../utils/request.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    testE:{}, // 主观视力检查 
    testS:{}, // 屈光视力检查 
    studentInfo:{}, // 学生信息 
    picture:'../../images/default-photo.png', // 头像
    isShow:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.toastDialog = this.selectComponent("#toastDialog");//此处id和页面的 wxml中的id一致
    this.queryReports(options)
    wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
  },
/**
 * 用户点击右上角分享
 */
onShareAppMessage (res) {
  return {
    title: '迪佳极视',
    path: 'pages/index/index',
    // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
    success: function (shareTickets) {
      console.info(shareTickets + '成功');
      // 转发成功
    },
    fail: function (res) {
      console.log(res + '失败');
      // 转发失败
    },
    complete:function(res){
      // 不管成功失败都会执行
    }
  }
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //获取报告详情
  queryReports: function (options) {
    var that = this
    that.toastDialog.showDialog({ code: 'loading', message: '加载中', timeout: false }); //loading 加载框
    request.postData('xcx/unlockStudent', options, function (res) {
      if (res.code == 0) {
        console.log(res)
        let picture = '../../images/default-photo.png'
        if(res.studentInfo.photo!=''){
          picture= res.studentInfo.photo
        }
        that.toastDialog.hideDialog(); //关闭loading提示框
        that.setData({
          testE:res.testE, // 主观视力检查 
          testS:res.testS, // 屈光视力检查 
          studentInfo:res.studentInfo, // 学生信息 
          picture:picture, // 学生信息 
          isShow:false
        })
      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }
    }, function (res) {
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });
  },
  //上传头像
  chooseImg:function(){
    var that = this;
    wx.chooseImage({
      count: 1,
      success: function (e) {
        that.setData({
          "picture": e.tempFilePaths[0],
        })
        var data = {photo:e.tempFilePaths,uid:that.data.studentInfo.id}
        wx.uploadFile({
          url: 'https://wxxcx.di.plus/djeye/xcx/updateStudentPhoto',
          filePath: e.tempFilePaths[0],
          header: { "openId": wx.getStorageSync("openid") }, 

          name: 'photo',
          formData: {
            'studentId': that.data.studentInfo.id
          },
          success: function (res) {
            console.log(res)
          }, fail: function (err) {
            console.log(err)
          }
        });
      },
      fail: function (e) {

      }
    })
  }

})